package com.hzhh123.download;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;

public class DownloadSettingActivity extends AppCompatActivity {
    private SharedPreferences sharedPreferences;
    private Switch aSwitch;
    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_download_setting);
        sharedPreferences=getSharedPreferences("download",MODE_PRIVATE);
        final SharedPreferences.Editor edit = sharedPreferences.edit();
        initToolbar();
        aSwitch=findViewById(R.id.switch1);
        if(sharedPreferences.getBoolean("open_download_notify",false)){
            aSwitch.setChecked(true);
        }
        aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked)
                {
                    edit.putBoolean("open_download_notify",true);
                }else{
                    edit.putBoolean("open_download_notify",false);
                }
                edit.commit();
            }
        });

        findViewById(R.id.download_list).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(DownloadSettingActivity.this,DownloadCompleteActivity.class));
            }
        });

    }

    private void initToolbar(){
       Toolbar toolbar = findViewById(R.id.toolbar);
        //设置标题和颜色
        toolbar.setTitle("下载设置");
        toolbar.setTitleTextColor(getResources().getColor(R.color.white));
        //返回菜单
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
